package com.zly.bscloud.sort;

import com.zly.bscloud.entity.Garbage;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

/**
 * @Author zhouxiaoyu
 * @Date 2020/5/6 9:08
 * @Version 1.0
 */
public class CompareFirst {
    public static List<Garbage> compareFist(List<Garbage> data) {
        Collections.sort(data, new Comparator<Garbage>() {

            Collator collator = Collator.getInstance(Locale.CHINA);

            @Override

            public int compare(Garbage o1, Garbage o2) {

                CollationKey key1 = collator.getCollationKey(o1.getName());

                CollationKey key2 = collator.getCollationKey(o2.getName());

                return key1.compareTo(key2);

            }

        });

        //for (Garbage garbage : data) {

         //   System.out.println(garbage.getName() + ":" + garbage.getCategory());

       // }

        return data;
    }


}
